package io.mft.commons.config.datasource;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.mft.commons.function.response.kv.KVMap;
import io.mft.commons.util.Unique;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
public class DSConfigSource implements Unique{
	private String ownerPluginId;
	//private String defaultSource="";
	private String type;
	private List<DatasourceConfig> datasources;
	private KVMap config=new KVMap();
	private List<KVMap> services;
	@Override
	public String uniqueId() {
		String id="";
		if (datasources!=null) {
			for (DatasourceConfig datasourceConfig : datasources) {
				id=id+"-"+datasourceConfig.uniqueId();
			}
		}
		return id;
	}
	
	public Map<String, DatasourceConfig> datasourceConfigMap() {
		Map<String, DatasourceConfig> map=new HashMap<String, DatasourceConfig>();
		if (datasources!=null) {
			datasources.forEach(d->{
				map.put(d.getId(), d);
			});
		}
		return map;
	}
}
